'use strict';


// Declare app level module which depends on filters, and services
angular.module('myApp', [
  'ngRoute',
  'myApp.services',
  'myApp.filters',
  'myApp.directives',
  'myApp.controllersMain',
  'myApp.controllersGame'
])
.config(['$routeProvider', function($routeProvider) {
    $routeProvider.when('/main',            {templateUrl: 'partials/main.html', controller: 'MainCtrl'});
    $routeProvider.when('/main/about',      {templateUrl: 'partials/main_about.html', controller: 'MainAboutCtrl'});
    $routeProvider.when('/main/setting',    {templateUrl: 'partials/main_setting.html', controller: 'MainSettingCtrl'});
    $routeProvider.when('/main/stats',      {templateUrl: 'partials/main_stats.html', controller: 'MainStatsCtrl'});
    $routeProvider.when('/game/single',     {templateUrl: 'partials/game.html', controller: 'GameSingleCtrl'});
    $routeProvider.when('/game/multi',      {templateUrl: 'partials/game.html', controller: 'GameMultiCtrl'});
    $routeProvider.when('/game/quit',       {templateUrl: 'partials/game_quit.html', controller: 'GameQuitCtrl'});
    $routeProvider.otherwise({redirectTo:   '/main'});
}])
.run(['serviceAppEvents',
    function (serviceAppEvents) {
        
        // back button
        document.addEventListener("backbutton", function(e) {
            e.preventDefault();
            serviceAppEvents.backbutton(e);
        }, true);
        
        document.addEventListener("gameend", function(e) {
            e.preventDefault();
            serviceAppEvents.gameend(e);
        }, true);
        
        var event = document.createEvent('Event');
        event.initEvent('appready', true, true);
        document.dispatchEvent(event);

    }
]);
